using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Security;
using DomesticBank.Models;


namespace DomesticBank.Controllers {
	[HandleError]
	public class AccountsController : Controller {
		[Authorize]
		public ActionResult Index() {
			AccountsData data = new AccountsData();
			List<Account> accounts = data.getAccounts((User)Session["user"]);
			ViewData["accounts"] = accounts;
			return View();
		}
		
		
		[Authorize]
		public ActionResult Add() {
			return View();
		}
		
		
		[Authorize]
		public ActionResult NewAccount(string name) {
			AccountsData data = new AccountsData();
			Account account = new Account();
			
			account.Name = name;
			account.User = new User();
			account.User.Id = ((User)Session["user"]).Id;
			
			data.addAccount(account);
			
			return RedirectToAction("Index");
		}
		
		
		[Authorize]
		public ActionResult Account(int id) {
			AccountsData data = new AccountsData();
			Account account = data.getAccount(((User)Session["user"]).Id, id);
			
			ViewData["account"] = account;
			
			return View();
		}
		
		
		[Authorize]
		public ActionResult Delete(int id) {
			AccountsData data = new AccountsData();
			
			data.deleteAccount(id);
			
			return RedirectToAction("Index");
		}
	}
}